package com.briup.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

public class CodeGenerator {
    private static  String url = "jdbc:mysql://localhost:3306/test";
    private static  String username = "root";
    private static  String password = "123456";
    private static  String basePackage = "com.briup";
    public static void main(String[] args) {
            FastAutoGenerator.create(url, username, password)
                    .globalConfig(builder -> builder
                            .author("syh")
                            .disableOpenDir()
                            .enableSwagger()
                            .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                            .commentDate("yyyy-MM-dd")
                    )
                    .packageConfig(builder -> builder
                            .parent(basePackage)
                            .entity("bean")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("web.controller")
                            .xml("mapper.xml")
                            .pathInfo(Collections.singletonMap(
                                    OutputFile.xml, Paths.get(System.getProperty("user.dir"))
                                            +"/src/main/resources/mapper"))
                    )
                .strategyConfig(builder -> builder
                        .likeTable(new LikeTable("cms_"))
//                        .addInclude("cms_role")
                        .addTablePrefix("Cms")
//                        .addFieldPrefix("t_")
                )
                .strategyConfig(builder -> builder
                        .entityBuilder()
                        .enableLombok()
                        .enableChainModel()
                        .enableTableFieldAnnotation()
                )
                .strategyConfig(builder -> builder
                        .controllerBuilder()
                        .enableRestStyle()
                        .enableFileOverride()
                )
                .strategyConfig(builder -> builder
                        .serviceBuilder()
                        .enableFileOverride()
                )
                .strategyConfig(builder -> builder
                        .mapperBuilder()
                        .enableBaseResultMap()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
